<template>
	<view>
		<view v-for="(tableItem,tableIndex) in value" :key="tableIndex" v-if="tableItem">
			<view class="formgtitle formpadding" style="width: 100%; background-color: #f0f2f6;">
				<view class="formgroup">
					<view class="labletitle font-size24"><label>{{item.__config__.label}}({{tableIndex+1}})</label>
					</view>
					<view class="controlvalue text-align-right font-size24">
						<text class="color-4869EE" @tap="removeDetailpro(item,tableIndex)"
							v-if="value.length > 1">删除</text>
					</view>
				</view>
			</view>
			<!-- 					<formControl v-for="(childItem, childIndex) in item.__config__.children" :key="childIndex" :item='childItem' :formData="formData" :formDataId="formDataId" :tableVmodel='tableVmodel'/> -->

			<view v-for="(childItem, childIndex) in item.__config__.children" :key="childIndex">
				<!-- 公司,部门,用户,岗位树组件 -->
				<view
					v-if="childItem.__config__.jnpfKey == 'comSelect' || childItem.__config__.jnpfKey == 'depSelect' || childItem.__config__.jnpfKey == 'userSelect' || childItem.__config__.jnpfKey == 'posSelect'">

					<!-- 公司 -->
					<view v-if="childItem.__config__.jnpfKey == 'comSelect'">
						<comSelect v-model="value[tableIndex][childItem.__vModel__]"
							:showLabel='childItem.__config__.showLabel' :placeholder="childItem.placeholder"
							:label='childItem.__config__.label' :disabled="childItem.disabled"
							:jnpfKey='childItem.__config__.jnpfKey' :vModel='childItem.__vModel__'></comSelect>
					</view>

					<!-- 部门 -->
					<view v-if="childItem.__config__.jnpfKey == 'depSelect'">
						<depSelect v-model="value[tableIndex][childItem.__vModel__]"
							:showLabel='childItem.__config__.showLabel' :placeholder="childItem.placeholder"
							:label='childItem.__config__.label' :disabled="childItem.disabled"
							:jnpfKey='childItem.__config__.jnpfKey' :vModel='childItem.__vModel__'></depSelect>
					</view>

					<!-- 用户 -->
					<view v-if="childItem.__config__.jnpfKey == 'userSelect'">
						<userSelect v-model="value[tableIndex][childItem.__vModel__]"
							:showLabel='childItem.__config__.showLabel' :placeholder="childItem.placeholder"
							:label='childItem.__config__.label' :disabled="childItem.disabled"
							:jnpfKey='childItem.__config__.jnpfKey' :vModel='childItem.__vModel__'></userSelect>
					</view>

					<!-- 岗位 -->
					<view v-if="childItem.__config__.jnpfKey == 'posSelect'">
						<posSelect v-model="value[tableIndex][childItem.__vModel__]"
							:showLabel='childItem.__config__.showLabel' :placeholder="childItem.placeholder"
							:label='childItem.__config__.label' :disabled="childItem.disabled"
							:jnpfKey='childItem.__config__.jnpfKey' :vModel='childItem.__vModel__'></posSelect>
					</view>
				</view>

				<!-- 输入 -->
				<view v-if="childItem.__config__.jnpfKey == 'jiushi-app' || childItem.__config__.jnpfKey == 'numInput'">
					<jiushi-app v-model="value[tableIndex][childItem.__vModel__]" :disabled="childItem.disabled"
						:type="childItem.__config__.jnpfKey"
						:maxlength='childItem.maxlength==null?controlProerty.maxlength:childItem.maxlength'
						:placeholder="childItem.placeholder" :showLabel='childItem.__config__.showLabel'
						:label='childItem.__config__.label' :tableModel='item.__vModel__' />
				</view>

				<!-- 选择框 -->
				<view
					v-if="childItem.__config__.jnpfKey == 'checkbox' || childItem.__config__.jnpfKey == 'radio' || childItem.__config__.jnpfKey == 'select'">
					<staticSelect v-model="value[tableIndex][childItem.__vModel__]"
						:jnpfKey='childItem.__config__.jnpfKey' :label='childItem.__config__.label'
						:vModel='childItem.__vModel__' :dataType='childItem.__config__.dataType'
						:disabled="childItem.disabled" :options='options' :showLabel='childItem.__config__.showLabel'
						:placeholder="childItem.placeholder" :propsLabel='childItem.__config__.props.label'
						:propsValue='childItem.__config__.props.value'
						:dictionaryType='childItem.__config__.dictionaryType' :propsUrl='childItem.__config__.propsUrl'
						:propsAll='childItem.__config__.props' />
				</view>

				<!-- 日期时间选择 -->
				<view v-if="childItem.__config__.jnpfKey == 'date' || childItem.__config__.jnpfKey == 'time'">
					<dateTime v-model="value[tableIndex][childItem.__vModel__]" :jnpfKey='childItem.__config__.jnpfKey'
						:label='childItem.__config__.label' :vModel='childItem.__vModel__'
						:disabled="childItem.disabled" :showLabel='childItem.__config__.showLabel'
						:placeholder="childItem.placeholder"></dateTime>
				</view>

				<!-- 树联，级联 -->
				<view v-if="childItem.__config__.jnpfKey == 'treeSelect' || childItem.__config__.jnpfKey == 'cascader'">
					<treeCascader v-model='value[tableIndex][childItem.__vModel__]'
						:jnpfKey='childItem.__config__.jnpfKey' :showLabel='childItem.__config__.showLabel'
						:placeholder="childItem.placeholder" :label='childItem.__config__.label'
						:disabled="childItem.disabled" :options='options' :vModel='childItem.__vModel__'
						:dictionaryType='childItem.__config__.dictionaryType' :tableModel='childItem.tableModel'
						:dataType='childItem.__config__.dataType'></treeCascader>
				</view>

				<!-- 省市区选择 -->
				<view v-if="childItem.__config__.jnpfKey == 'address'">
					<addressSelect v-model='value[tableIndex][childItem.__vModel__]'
						:jnpfKey='childItem.__config__.jnpfKey' :showLabel='childItem.__config__.showLabel'
						:placeholder="childItem.placeholder" :label='childItem.__config__.label'
						:disabled="childItem.disabled" :vModel='childItem.__vModel__'></addressSelect>
				</view>

				<!-- 日期范围 -->
				<view v-if="childItem.__config__.jnpfKey == 'dateRange'">
					<rangeTime v-model='value[tableIndex][childItem.__vModel__]'
						:showLabel='childItem.__config__.showLabel' :placeholder="childItem.placeholder"
						:label='childItem.__config__.label' :disabled="childItem.disabled"></rangeTime>
				</view>

				<!-- 开关 -->
				<view v-if="childItem.__config__.jnpfKey == 'switch'">
					<JNPFSwitch :vModel='childItem.__vModel__' v-model="value[tableIndex][childItem.__vModel__]"
						:disabled="childItem.disabled" :showLabel='childItem.__config__.showLabel'
						:label='childItem.__config__.label'></JNPFSwitch>
				</view>

				<!-- 系统自动生成 -->
				<view
					v-if="childItem.__config__.jnpfKey == 'billRule' || childItem.__config__.jnpfKey == 'createUser' || childItem.__config__.jnpfKey == 'currDept' || childItem.__config__.jnpfKey == 'createTime' || childItem.__config__.jnpfKey == 'modifyUser' || childItem.__config__.jnpfKey == 'modifyTime' || childItem.__config__.jnpfKey == 'currPosition' || childItem.__config__.jnpfKey == 'currOrganize'">
					<autoGenerate v-model="value" :disabled="childItem.disabled" :jnpfKey="childItem.__config__.jnpfKey"
						:placeholder="childItem.placeholder" :showLabel='childItem.__config__.showLabel'
						:label='childItem.__config__.label'></autoGenerate>
				</view>

			</view>
		</view>
		<!-- 点击添购 -->
		<view class="formlist inputtext" @tap="addChildren(item)">
			<view class="formgroup border-bottom-E3E3E5">
				<view class="second-title color-4869EE">
					<label class="iconfont icon-jia font-size28"></label>{{item.actionText}}
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import JNPFText from '@/components/JNPFText/JNPFText.vue'
	import groupTitle from '@/components/groupTitle/groupTitle.vue'
	import staticSelect from '@/components/staticSelect/staticSelect.vue'
	import treeCascader from '@/components/treeCascader/treeCascader.vue'
	import rangeTime from '@/components/range-picker/rangeTime.vue'
	import addressSelect from '@/components/addressSelect/addressSelect.vue'
	import comSelect from '@/components/comSelect/comSelect.vue'
	import depSelect from '@/components/depSelect/depSelect.vue'
	import userSelect from '@/components/userSelect/userSelect.vue'
	import posSelect from '@/components/posSelect/posSelect.vue'
	import ymTextarea from '@/components/ym-Textarea/ym-Textarea.vue'
	import comInput from '@/components/comInput/comInput.vue'
	import dateTime from '@/components/dateTime/dateTime.vue'
	import autoGenerate from '@/components/autoGenerate/autoGenerate.vue'
	import JNPFSlider from '@/components/JNPFSlider/JNPFSlider.vue'
	import JNPFSwitch from '@/components/JNPFSwitch/JNPFSwitch.vue'
	import JNPFRate from '@/components/JNPFRate/JNPFRate.vue'
	import JNPFUpload from '@/components/JNPFUpload/JNPFUpload.vue'
	export default {
		components: {

			staticSelect,
			treeCascader,
			rangeTime,
			addressSelect,
			comSelect,
			depSelect,
			userSelect,
			posSelect,
			ymTextarea,
			comInput,
			dateTime,
			autoGenerate,
			JNPFSlider,
			JNPFSwitch,
			JNPFText,
			groupTitle,
			JNPFRate,
			JNPFUpload,
		},
		name: 'formControl',
		props: {
			item: {
				type: Object,
				default: () => ({})
			},
			value: {
				type: Array,
				default: () => ([])
			},
			options: {
				type: Array,
				default () {
					return [{
						fullName: '默认一',
						id: '1'
					}, {
						fullName: '默认二',
						id: '2'
					}]
				}
			},
			scanType: {
				type: Boolean,
				default () {
					return false
				}
			},
		},
		data() {
			return {
				tableVmodel: [],
				controlProerty: { //控件属性
					maxlength: 50,
				},
				depList: [],
				comList: [],
				userList: [],
				postList: [],
			};
		},
		created() {

		},

		methods: {
			removeDetailpro(item, tableIndex) {
				if (this.scanType) {
					this.$helper.msg('功能预览不支持删除子表')
					return
				}
				this.$forceUpdate();
				this.value.splice(tableIndex, 1);
				this.$forceUpdate();
			},

			/* 添加子表 */
			addChildren(item) {
				if (this.scanType) {
					this.$helper.msg('功能预览不支持新增子表')
					return
				}

				this.$forceUpdate()
				let childItem = {}
				let list = this.value
				for (var j = 0; j < item.__config__.children.length; j++) {
					let e = item.__config__.children[j]
					childItem[e.__vModel__] = e.__config__.defaultValue
				}
				this.value.push(childItem)
				this.$forceUpdate()

			}
		}
	}
</script>

<style>

</style>